import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:random_lottery_ticket/random_data.dart';
import 'package:random_lottery_ticket/random_dialog.dart';
import 'customize_widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'service.dart';
import 'package:toast/toast.dart';

class Random extends StatefulWidget {
  @override
  _RandomState createState() => _RandomState();
}

class _RandomState extends State<Random> {
  int _randomType = -1;
  Widget _randomWidget;

  final  CRRBController = new TextEditingController();
  final  CRBBController = new TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: [
          Padding(padding: EdgeInsets.fromLTRB(0, 30, 0, 0)),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              FloatingActionButton.extended(
                label: Text('普通随机'),
                highlightElevation: 30,
                onPressed: () {
                  print('普通随机');
                  setState(() {
                    _randomWidget = NormalRandomWidget();
                    _randomType = 0;
                  });
                },
              ),
              FloatingActionButton.extended(
                label: Text('胆拖随机'),
                highlightElevation: 30,
                onPressed: () {
                  print('胆拖随机');
                  setState(() {
                    _randomType = 1;
                    _randomWidget = CustomizeWidgets().danTuoRandomWidget();
                  });
                },
              ),
              FloatingActionButton.extended(
                label: Text('复式随机'),
                highlightElevation: 30,
                onPressed: () {
                  print('复式随机');
                  setState(() {
                    _randomType = 2;
                    _randomWidget = CompoundRandomWidget(CRRBController,CRBBController);
                  });
                },
              ),
            ],
          ),
          Padding(padding: EdgeInsets.fromLTRB(0, 30, 0, 0)),
          Container(
            width: ScreenUtil().setWidth(1000),
            height: ScreenUtil().setHeight(800),
            decoration: BoxDecoration(
              border: Border.all(color: Colors.red, width: 1),
              borderRadius: BorderRadius.all(
                //圆角
                Radius.circular(20.0),
              ),
            ),
            child: _randomWidget,
          ),
          Padding(padding: EdgeInsets.fromLTRB(0, 30, 0, 0)),
          CupertinoButton(
              color: Colors.red,
              disabledColor: Colors.cyanAccent,
              borderRadius: BorderRadius.all(Radius.circular(36.0)),
              child: Text('我要随机双色球'),
              onPressed: () {
                switch(_randomType){
                  case 0:
                    var ssqs = RandomService()
                        .NormalRandom(context.read<RandomNumber>().number, 0);
                    print(ssqs.toString());
                    print('ssq');
                    showDialog(
                        context: context,
                        builder: (BuildContext context) {
                          return RandomSSQDialog(ssqs);
                        });
                    break;
                  case 1:
                    Toast.show("作者懒，不想写了...", context, duration: Toast.LENGTH_LONG, gravity:  Toast.CENTER);
                    break;
                  case 2:
                    setState(() {
                      _randomWidget = CompoundRandomWidget(CRRBController,CRBBController);
                    });
                    int rbnum = int.parse(CRRBController.text,onError: (source) => 0);
                    int bbnum = int.parse(CRBBController.text,onError: (source) => 0);
                    Toast.show("作者懒，不想写了...", context, duration: Toast.LENGTH_LONG, gravity:  Toast.CENTER);

                    break;
                  default:
                    Toast.show("先选择要随机的种类啊", context, duration: Toast.LENGTH_SHORT, gravity:  Toast.BOTTOM);
                }

              }),
          Padding(padding: EdgeInsets.fromLTRB(0, 30, 0, 0)),
          CupertinoButton(
              color: Colors.red,
              disabledColor: Colors.cyanAccent,
              borderRadius: BorderRadius.all(Radius.circular(36.0)),
              child: Text('我要随机大乐透'),
              onPressed: () {
                  switch(_randomType){
                    case 0:
                      var dlts = RandomService()
                          .NormalRandom(context.read<RandomNumber>().number, 1);
                      print('dlt');
                      print(dlts.toString());
                      showDialog(
                          context: context,
                          builder: (BuildContext context) {
                            return RandomDLTDialog(dlts);
                          });
                      break;
                    case 1:
                      Toast.show("作者懒，不想写了...", context, duration: Toast.LENGTH_LONG, gravity:  Toast.CENTER);
                      break;
                    case 2:
                      setState(() {
                        _randomWidget = CompoundRandomWidget(CRRBController,CRBBController);
                      });
                      Toast.show("作者懒，不想写了...", context, duration: Toast.LENGTH_LONG, gravity:  Toast.CENTER);
                      break;
                    default:
                      Toast.show("先选择要随机的种类啊", context, duration: Toast.LENGTH_SHORT, gravity:  Toast.BOTTOM);
                  }

              }),
          Padding(padding: EdgeInsets.fromLTRB(0, 30, 0, 0)),
        ],
      ),
    );
  }
}
